import { useCallback } from "react";
import { useSelector, useDispatch } from "react-redux";
import navsApi from "../api/navs";
import Creators from "../store/actions";

export const useNavs = () => {
  const navs = useSelector((state) => state.navs);
  const dispatch = useDispatch();
  //获取商品大类数据
  const getAllNavs = useCallback(async () => {
    const data = await navsApi.get();
    // console.log(data);
    dispatch(Creators.getAllNavs(data));
  }, [dispatch]);
  return [navs,{ getAllNavs }];
};
